﻿<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ include file="/WEB-INF/view/jsp/base.jsp" %>
<html lang="en">
<body>
	<div id="content">
		<div id="content-header"></div>
		<div class="container-fluid">
			<div class="widget-box">
				<div class="widget-title">
					<h5>列表</h5>
			    </div>
				<div class="widget-content nopadding">
					<table id="userTable" url="<%=path%>/user/getList" class="table table-bordered data-table ">
						<thead>
							<tr role="row">
								<th class="ui-state-default" role="columnheader"  style="width: 20%;" name="userId" primaryKey="true">UserId</th>
								<th class="ui-state-default" role="columnheader"  style="width: 20%;" name="userName">userName</th>
								<th class="ui-state-default" role="columnheader"  style="width: 20%;" name="email">Email</th>
								<th class="ui-state-default" role="columnheader"  style="width: 20%;" name="certNo">certNo</th>
								<th class="ui-state-default" role="columnheader"  style="width: 20%;" name="mobile">mobile</th>
								<th class="ui-state-default" role="columnheader"  style="width: 20%;" name="work-box"></th>
							</tr>
						</thead>
						<tbody role="alert" aria-live="polite" aria-relevant="all">
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
	
	<div id="modelDialog" class="modal hide fade in" style="display:none;">
		<div class="modal-header">
			<a class="close" data-dismiss="modal">x</a>
			<h4>操作提示</h4>
		</div>
		<div class="modal-body">
			<h4>确认删除该项记录吗？</h4>
		</div>
		<div class="modal-body">
			<button id="confirm" type="button" class="btn btn-success">确认</button>
			<button  type="button class="btn btn-default" data-dismiss="modal">关闭</button>
		</div>
	</div>

</body>
     <script type="text/javascript">
     
    	    var param = C.getParams("${param}"); //接收传参
    	    //加载数据
    	    toPage();
            
    	    //分页函数
    	    function toPage(pageNum){
    	    	if(pageNum == 0){
    	    		return ;
    	    	}
    	    	param.pageNum = pageNum?pageNum:1;
    	    	C.load($("#userTable"),param);
    	    }
    	    
     	    //编辑
     		function edit(id){
     			window.location.href="<%=path%>/user/form?id="+id+"&pageNum="+param.pageNum;
     		}   		
     		
    		
     		//删除
     		function del(id,_this){
     			var _tr = _this.parent().parent();
     			var sib = _tr.siblings("tr").length;
    			$("#modelDialog").modal();
    			$("#confirm").click(function(){
	      			$.ajax({
	      				url:"<%=path %>/user/del",
	      				data:{"userId":id},
	      				type:"post",
	      				success:function(text){
	      					if(text.success){
	      						C.gritter("删除成功！");
	      						if(sib==0){
	          						//删除完成刷新当前页（删除的数据为当前页唯一条时，pageNum-1）
	          						_tr.remove();  //如果删除的记录为当前结果集的唯一一条，前后台同时做删除操作
	          						toPage((param.pageNum-1)>0?param.pageNum-1:1);
	          					}else{
	          						//删除完成刷新当前页
	          						toPage(param.pageNum);	
	          					}
	      					}else{
	      						C.gritter("删除失败！");
	      					}
	      				}
	      			});
    			});
     		}

     </script>
</html>